use std::error::Error;

use cs2s::command::{CommandQueueClientHandle, TerminateStatus};

use crate::{args::ServerStopCommand, ARGS};

/// Stops the server.
pub fn stop(command: &ServerStopCommand) -> Result<(), Box<dyn Error>> {
    CommandQueueClientHandle::terminate(
        &ARGS.name,
        if command.fail {
            TerminateStatus::Failure
        } else {
            TerminateStatus::Success
        },
    )
    .map_err(Into::into)
}
